package com.zq.blog_serve.common;

import lombok.Data;

@Data
public class AjaxResult {

    private int code;

    private String msg;

    private Object data;

    public static AjaxResult success() {
        return new AjaxResult(AjaxResultState.SUCCESS);
    }

    public static AjaxResult error() {
        return new AjaxResult(AjaxResultState.ERROR);
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(AjaxResultState.SUCCESS, null, data);
    }

    public static AjaxResult error(String msg) {
        return new AjaxResult(AjaxResultState.ERROR, msg, null);
    }

    public AjaxResult(AjaxResultState state) {
        this.code = state.getCode();
        this.msg = state.getMsg();
        this.data = null;
    }

    public AjaxResult(AjaxResultState state, String msg, Object data) {
        this.code = state.getCode();
        this.msg = msg != null ? msg : state.getMsg();
        this.data = data;
    }
}
